home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_09_06
/
9n06086b
< prev
next >
Wrap
Text File
|
1990-02-27
|
3KB
|
116 lines
/**************************************************************************
ffc.c
Format File in Columns.
Invocation:
% ffc [-c num] [-d] [-h num] [-l num]
[-o output_file] [-p] [input_file(s)]
where
"-c <num>"
specifies the number of columns (default = 2).
"-d"
turns debug output on.
"-h <num>"
specifies the number of blank lines at the top of each
page (default = 0).
"-l <num>"
specifies the number of lines per page (default = 66).
"-o <output_file>"
specifies the name of the output file (default =
standard output).
"-p"
invokes page numbering on output.
<input_file(s)>
are the files to be read and formatted in columns on
output (default = standard input).
Compilation:
The program should be compiled and linked with the
GETOPT function:
% cc ffc.c getopt.c -o ffc
**************************************************************************/
#include <stdio.h> /* Standard I/O definitions. */
#include "getopt.h" /* GETOPT(3) definitions. */
/* List of input file names. */
#define MAX_FILES 1024
static char *file_table[MAX_FILES] ;
static int num_input_files = 0 ;
/* Page dimensions, etc. */
static int debug = 0 ; /* 0 = no, -1 = yes. */
static int num_columns = 2 ;
static int num_header_lines = 0 ;
static int page_length = 66 ;
static int page_numbering = 0 ; /* 0 = no, -1 = yes. */
main (argc, argv)
int argc ;
char *argv[] ;
{ /* Local variables. */
char *output_file = NULL ;
int errflg, option ;
/* Scan the command line arguments. */
errflg = 0 ;
while (((option = getopt (argc, argv, "c:dh:l:o:p")) != NONOPT) ||
(optarg != NULL)) {
printf ("Option = '%c' Argument = \"%s\"\n", option, optarg) ;
switch (option) {
case 'c': num_columns = atoi (optarg) ; break ;
case 'd': debug = -1 ; break ;
case 'h': num_header_lines = atoi (optarg) ; break ;
case 'l': page_length = atoi (optarg) ; break ;
case 'o': output_file = optarg ; break ;
case 'p': page_numbering = -1 ; break ;
case '?': errflg++ ; break ;
case NONOPT:
if (num_input_files < MAX_FILES) {
file_table[num_input_files++] = optarg ;
}
break ;
default : break ;
}
}
/* If an invalid option was detected, print out a command usage message. */
if (errflg) {
fprintf (stderr, "Usage: ffc [-c num] [-d] [-h num]\n") ;
fprintf (stderr, " [-l num] [-o output_file]\n") ;
fprintf (stderr, " [-p] [input_file(s)]\n") ;
exit (-1) ;
}
/* Print out the files in multiple columns. */
/* ... the remainder of the program ... */
}